<template>
  <div id="app">
    <div class="header">
      <h1>我是header</h1>
      <button @click="logout">退出登录</button>
    </div>
    <div class="middle">
      <div class="left">
        <div @click="shouyeManager" :class="this.$store.state.index==0 ? 'sidebar2':'sidebar'">
          <i class="iconfont iconshouye"></i>首页
        </div>
        <div v-if="this.$store.state.user.shop" @click="shopManager" :class="this.$store.state.index==1 ? 'sidebar2':'sidebar'">
          <i class="iconfont iconshangpinguanli"></i>商品管理
        </div>
        <div  v-if="this.$store.state.user.user" @click="userManager" :class="this.$store.state.index==2 ? 'sidebar2':'sidebar'">
          <i class="iconfont iconyonghuguanli" ></i>用户管理
        </div>
        <div  v-if="this.$store.state.user.staff" @click="staffManager" :class="this.$store.state.index==3 ? 'sidebar2':'sidebar'">
          <i class="iconfont iconyuangongguanli"></i>员工管理
        </div>
      </div>
      <div class="right">
        <router-view></router-view>
      </div>
    </div>

    <div class="footer">我是footer</div>
  </div>
</template>


<script>
export default {
  name: "home",
  props: [],
  components: {},
  data() {
    return {};
  },
  //方法 函数写这里
  methods: {
    shouyeManager() {
      this.$store.commit("shouyeManager", 0);
      this.$router.push("/home/shouye");
    },
    shopManager() {
      this.$store.commit("shopManager", 1);
      this.$router.push("/home/shop");
    },
    userManager() {
      this.$store.commit("userManager", 2);
      this.$router.push("/home/user");
    },
    staffManager() {
      this.$store.commit("staffManager", 3);
      this.$router.push("/home/staff");
    },
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    }
  },
  //计算属性
  computed: {},
  //侦听器
  watch: {},
  //过滤器
  filters: {},
  //以下是生命周期
  //组件创建之前
  beforeCreate() {},
  //组件创建之后
  created() {
    var a = this.$store.state.index;
    if (a == 0) {
      this.$router.push("/home/shouye");
    } else if (a == 1) {
      this.$router.push("/home/shop");
    } else if (a == 2) {
      this.$router.push("/home/user");
    } else {
      this.$router.push("/home/staff");
    }
  },
  //页面渲染之前
  beforeMount() {},
  //页面渲染之后
  mounted() {},
  //页面视图数据更新之前
  beforeUpdate() {},
  //页面视图数据更新之后
  updated() {},
  //页面销毁之前
  beforeDestroy() {},
  //页面销毁之后
  destroyed() {}
};
</script>
<style lang="scss">
#app{
  height: 100%;
  display: flex;
  flex-direction: column;
}
.header {
  width: 100%;
  height: 6vh;
  background-color: #2a5caa;
  color: white;
  text-align: center;
  line-height: 6vh;
  display: flex;
  justify-content: space-between;
  align-items: center;
  button {
    width: 80px;
    height: 30px;
    line-height: 30px;
    background-color: springgreen;
    margin-right: 200px;
  }
  h1 {
    margin-left: 20px;
  }
}
.footer {
  width: 100%;
  height: 6vh;
  position: fixed;
  left: 0;
  bottom: 0;
  color: white;
  text-align: center;
  line-height: 6vh;
  background-color: skyblue;
}

.middle {
  flex: 1;
  display: flex;
  width: 100%;
  height: 90vh;
  min-height: 90vh;
}

.left {
  width: 180px;
  height: 100%;
  background-color: slateblue;
  div i{
    padding: 0px 5px 0px 20px;
  }
}

.right {
  flex: 1;
  overflow-y: scroll;
  height: 100%;
  background-color: gainsboro;
}

.sidebar2 {
  height: 30px;
  margin-top: 10px;
  background-color: black;
  color: white;
  cursor: pointer;
  line-height: 30px;
}

.sidebar {
  height: 30px;
  margin-top: 10px;
  background-color: skyblue;
  color: white;
  cursor: pointer;
  line-height: 30px;
}
</style>
